package com.zhiwang.xiaoqu.widget.webview

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.MotionEvent
import android.webkit.WebView

class WebViewEx : WebView {

    var onScrollChangeListener: OnScrollChangeListener? = null
    var onTouchListener: OnTouchListener? = null

    val TAG = "WebViewEx"

    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    override fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) {
        super.onScrollChanged(l, t, oldl, oldt)

        onScrollChangeListener?.onScrollChange(l, t, oldl, oldt)
    }

    override fun onTouchEvent(event: MotionEvent?): Boolean {
        onTouchListener?.onTouch()
        return super.onTouchEvent(event)
    }

    interface OnScrollChangeListener {
        fun onScrollChange(l: Int, t: Int, oldl: Int, oldt: Int)
    }

    interface OnTouchListener {
        fun onTouch()
    }
}